//
//  BalanceTableViewCell.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/11/24.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "BalanceTableViewCell.h"

@implementation BalanceTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setMainView];
    }
    return self;
}

- (void)setMainView
{
    if (!self.titleLab) {
        self.titleLab = [UILabel new];
        self.titleLab.textColor = UIColorFromHex(0x020200);
        self.titleLab.font = FontSemiboldSize(14);
        self.titleLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"充值"];
        [self addSubview:self.titleLab];
    }
    if (!self.desLab) {
        self.desLab = [UILabel new];
        self.desLab.textColor = UIColorFromHex(0x9F9F9F);
        self.desLab.font = FontWithSize(14);
        self.desLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"支付贷款"];
        [self addSubview:self.desLab];
    }
    if (!self.timeLab) {
        self.timeLab = [UILabel new];
        self.timeLab.textColor = UIColorFromHex(0x9F9F9F);
        self.timeLab.font = FontWithSize(12);
        self.timeLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"08-07 21:45"];
        [self addSubview:self.timeLab];
    }
    if (!self.moneyLab) {
        self.moneyLab = [UILabel new];
        self.moneyLab.textColor = UIColorFromHex(0x020200);
        self.moneyLab.font = FontSemiboldSize(14);
        self.moneyLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"+2000"];
        self.moneyLab.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.moneyLab];
    }
    if (!self.useLab) {
        self.useLab = [UILabel new];
        self.useLab.textColor = UIColorFromHex(0x9F9F9F);
        self.useLab.font = FontWithSize(12);
        self.useLab.textAlignment = NSTextAlignmentRight;
        self.useLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:1 and:@"可用¥2000"];
        [self addSubview:self.useLab];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.titleLab.frame = CGRectMake(15, 20, 40, 14);
    CGSize size = [TTKUtil sizeWithText:@"扣除余额" Height:14 Font:FontSemiboldSize(14)];
    self.desLab.frame = CGRectMake(size.width+5, self.titleLab.top, 150, 14);
    self.timeLab.frame = CGRectMake(self.titleLab.left, self.titleLab.bottom+10, 200, 12);
    self.moneyLab.frame = CGRectMake(self.width-100, 15, 85, 14);
    self.useLab.frame = CGRectMake(self.width-120, self.moneyLab.bottom+10, 105, 12);
}

- (void)getModel:(BalanceModel *)model
{
    self.titleLab.text = [NSString stringWithFormat:@"%@",model.capitalTypeDesc];
    self.desLab.text = [NSString stringWithFormat:@"%@",model.flowTypeDesc];
    self.timeLab.text = [NSString stringWithFormat:@"%@",model.time];
    self.moneyLab.text = [NSString stringWithFormat:@"%.2f",[model.amount doubleValue]];
    self.useLab.text = [NSString stringWithFormat:@"%.2f",[model.left doubleValue]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
